package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Slf4j
@Api("c端-用户下单")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> selectOrderDetails(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersService.selectOrderDetails(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */

    @GetMapping("/details/{id}")
    public Result ViewOrderDetails(@PathVariable Integer id){
        //前端传来的是订单的id
        OrderVO orderVO = ordersService.ViewOrderDetails(id);
        return Result.success(orderVO);
    }


    /**
     * 查看各个订单的数据统计
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getStatistics(){
        //分别是待派送，待接单，派送中是数据需要
        OrderStatisticsVO orderStatisticsVO = ordersService.getStatistics();
        return Result.success(orderStatisticsVO);
    }


    @PutMapping("/cancel")
    public Result CancelTheOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordersService.CancelTheOrder(ordersCancelDTO);
        return Result.success();
    }


    @PutMapping("/rejection")
    public Result Declines(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.Declines(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    public Result TakeOrders(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.TakeOrders(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result finish(@PathVariable Integer id){
        ordersService.finish(id);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    public Result Delivery(@PathVariable Integer id){
        ordersService.Delivery(id);
        return Result.success();
    }





}
